home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Info / TeachU14 / SAMS / Code / Day06 / winhello.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-08  |  1.7 KB  |  76 lines

  1. #define STRICT
  2. #include <windows.h>
  3. #pragma hdrstop
  4.  
  5. LRESULT FAR PASCAL _export WndProc(HWND, UINT, WPARAM, LPARAM);
  6.  
  7. int PASCAL WinMain(HINSTANCE hInstance,
  8.   HINSTANCE hPrevInstance, LPSTR lpszCmd, int nCmdShow)
  9. {
  10.   static char AppName[] = "HelloWorld";
  11.   HWND        hwnd;
  12.   MSG         msg;
  13.   WNDCLASS    wndclass;
  14.   if (!hPrevInstance)
  15.   {
  16.     wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  17.     wndclass.lpfnWndProc   = (WNDPROC)WndProc;
  18.     wndclass.cbClsExtra    = 0;
  19.     wndclass.cbWndExtra    = 0;
  20.     wndclass.hInstance     = hInstance;
  21.     wndclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  22.     wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  23.     wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  24.     wndclass.lpszMenuName  = 0;
  25.     wndclass.lpszClassName = AppName;
  26.  
  27.     RegisterClass(&wndclass);
  28.   }
  29.  
  30.   hwnd = CreateWindow(AppName,
  31.     "Hello World",
  32.     WS_OVERLAPPEDWINDOW,
  33.     CW_USEDEFAULT,
  34.     CW_USEDEFAULT,
  35.     CW_USEDEFAULT,
  36.     CW_USEDEFAULT,
  37.     NULL,
  38.     NULL,
  39.     hInstance,
  40.     NULL);
  41.  
  42.   ShowWindow(hwnd, SW_NORMAL);
  43.  
  44.   while (GetMessage(&msg, NULL, 0, 0))
  45.   {
  46.     TranslateMessage(&msg);
  47.     DispatchMessage(&msg);
  48.   }
  49.   return msg.wParam;
  50. }
  51.  
  52. LRESULT FAR PASCAL _export
  53. WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  54. {
  55.   switch(message)
  56.   {
  57.     case WM_PAINT :
  58.     {
  59.       char text[] = "Hello World!!";
  60.       PAINTSTRUCT ps;
  61.       BeginPaint(hwnd, &ps);
  62.       TextOut(ps.hdc, 20, 20, text, 13);
  63.       EndPaint(hwnd, &ps);
  64.       break;
  65.     }
  66.     case WM_DESTROY : {
  67.       PostQuitMessage(0);
  68.       return 0;
  69.     }
  70.     default:
  71.       return DefWindowProc(hwnd, message, wParam, lParam);
  72.   }
  73.   return 0;
  74.  
  75.